﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EvoWars.Stuffs;
using EvoWars.Stuffs.TankStuff;
using EvoWars2.Stuffs.AI;

namespace EvoWars2.Stuffs.TankStuff
{
    class TankFactory
    {
        private static Random rand;
        public static Random Rand
        {
            get
            {
                if (rand == null)
                {
                    rand = new Random();

                }
                return rand;
            }
        }

        private static TankAttributes defaultAttributes;
        public static TankAttributes DefaultAttributes
        {
            get
            {
                if (defaultAttributes == null)
                {
                    defaultAttributes = new TankAttributes();
                    defaultAttributes.Acceleration = 0m;
                    defaultAttributes.MaxHealth = 100m;
                    defaultAttributes.MaxSpeed = 7m;
                    defaultAttributes.ShotCooldown = new TimeSpan(0, 0, 0, 1);
                    defaultAttributes.ShotMaxDistance = 5000m;
                    defaultAttributes.ShotPower = 10m;
                    defaultAttributes.ShotSpeed = 30m;
                }

                return defaultAttributes;

            }

        }



        private static int tankId = 0;



        public static Tank MakeDefaultTank(World theWorld)
        {
            Tank myTank = new Tank();

            myTank.Attributes = DefaultAttributes;
            myTank.Id = GetNextTankId();
            myTank.CurrentHealth = myTank.Attributes.MaxHealth;
            myTank.CurrentVelocity = new Microsoft.Xna.Framework.Vector2(0f, 0f);
            int tankWidth = 56;
            int tankHeight = 57;
            myTank.BoundingBox = new Microsoft.Xna.Framework.Rectangle(0, 0, tankWidth, tankHeight);

            IArtificialIntelligence ai = new NullAI();
            ai.Parent = myTank;
            ai.Init();
            myTank.AI = ai;
            myTank.Sensor = new TankSensor(myTank, theWorld);


            return myTank;
        }


        public static Tank MakeBouncerAITank(World theWorld)
        {
            Tank myTank = MakeDefaultTank(theWorld);

            BouncerAI ai = new BouncerAI();
            ai.Parent = myTank;
            ai.Rand = Rand;
            ai.Init();
            myTank.AI = ai;

            return myTank;


        }

        public static Tank MakeWandererAITank(World theWorld)
        {
            Tank myTank = MakeDefaultTank(theWorld);

            WandererAI ai = new WandererAI();
            ai.Parent = myTank;
            ai.Rand = Rand;
            ai.Init();
            myTank.AI = ai;

            return myTank;


        }

        private static int GetNextTankId()
        {
            int nextId = tankId;
            tankId++;
            return nextId;
        }


    }
}
